<?
if (!defined('IN_MEDIA')) die("Hacking attempt");
function box_user_online() {
	global $mysql, $tb_prefix, $tpl, $web_type, $mainURL;
	$timeout = 60*30;
	$total = 0;	$member = 0; $guest = 0;
	$current_time = NOW;
	$time_exit = $current_time - $timeout;
	$mysql->query("DELETE FROM ".$tb_prefix."online WHERE timestamp < ".$time_exit);
	$member_sql = $mysql->query("SELECT user_id, user_name, user_level FROM ".$tb_prefix."user WHERE user_online = 1 AND user_timeout > ".$time_exit." ORDER BY user_timeout DESC");
	$members = $mysql->num_rows($member_sql);
	$total = $guests + $members;
	
	while($r = $mysql->fetch_array($member_sql)){
		$id = $r['user_id'];
		$level = $r['user_level'];
		$name = $r['user_name'];
		if( $level == 3 )
		{
			$name = "<font color=#CC0000 >".$name."</font>";
		}
		if( $level == 2 )
		{
			$name = "<font color=#FF9900 >".$name."</font>";
		}		
		$user_URL 	= url_link($id,$name,'User');
		$user_LEVEL	= m_get_data('USER',$id,'user_level');
			switch($user_LEVEL) {
				case 1 : $class = 'a_mem'; break;
				case 2 : $class = 'a_mod'; break;
				case 3 : $class = 'a_admin'; break;
			}
		$online_HTML .= "<li><a href='$user_URL'>$name</a></li>";
	}
	include("templates/".$_SESSION['current_tpl']."/boxes/user_online.html");

}
?>